package com.eliaukjq.javase;

/**
 * @Author : 佩萁
 * Description :内部类测试
 * @Create : 2023/11/29 - 16:23
 */
public class InnerClass {
    public class Inner {
        private int data = 10;

        //成员内部类不能包含static的变量和方法
        //static String da = "11";
        void message() {
            System.out.println("data");
        }
    }

    public void a() {
        Inner inner = new Inner();
        inner.message();
    }

    public void doSomething(){
        final int x = 10;
        class inner2{
            void message(){
                System.out.println("局部内部类");
            }
        }
        inner2 inner2 = new inner2();
        inner2.message();
    }

    public void doSomething2(){
        Runnable runnable = new Runnable(){
//            static int x = 1;
            @Override
            public void run() {
                System.out.println("匿名内部类");
            }
        };
        Thread thread = new Thread(runnable);
        thread.run();
    }
    static int x = 1;
    int y = 2;
    static class StaticInnerClass{
        void play(){
            System.out.println("静态内部类");
            System.out.println(x);
            //System.out.println(y);报错
        }
    }
    public static void main(String[] args) {
        InnerClass innerClass = new InnerClass();
        innerClass.a();
        innerClass.doSomething();
        innerClass.doSomething2();
        StaticInnerClass staticInnerClass = new StaticInnerClass();
        staticInnerClass.play();
    }
}
